package com.hmall.pojo;


import com.hmall.common.dto.Item;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @Author dml
 * Date on 2022/7/11 0011
 */

@Data
@NoArgsConstructor
public class ItemDoc {
//    private Long id;//商品id
//    private String name;//商品名称
//    private Long price;//价格（分）
//    private Integer stock;//库存数量
//    private String image;//商品图片
//    private String category;//分类名称
//    private String brand;//品牌名称
//    private String spec;//规格
//    private Integer sold;//销量
//    private Integer commentCount;//评论数
//    private Integer status;//商品状态 1-正常，2-下架
//    private Boolean isAD;//商品状态 1-正常，2-下架
//    private Date createTime;//创建时间
//    private Date updateTime;//更新时间
//    private List<String> suggestion;
//
//    public ItemDoc(Item item) {
//        this.id = item.getId();
//        this.name = item.getName();
//        this.price = item.getPrice();
//        this.stock = item.getStock();
//        this.image = item.getImage();
//        this.category = item.getCategory();
//        this.brand = item.getBrand();
//        this.spec = item.getSpec();
//        this.sold = item.getSold();
//        this.commentCount = item.getCommentCount();
//        this.status = item.getStatus();
//        this.isAD = item.getIsAD();
//    /*    this.createTime = item.getCreateTime();
//        this.updateTime = item.getUpdateTime();*/
//
//        // 组装suggestion
//        this.suggestion = Arrays.asList(this.brand, this.category);
////        if(this.category.contains("/")){
////            // business有多个值，需要切割
////            String[] arr = this.category.split("/");
////            // 添加元素
////            this.suggestion = new ArrayList<>();
////            this.suggestion.add(this.brand);
////            Collections.addAll(this.suggestion, arr);
////        }else {
////            this.suggestion = Arrays.asList(this.brand, this.category);
////
////
////        }
//    }

    private Long id;
    private String name;
    private Long price;
    private Integer stock;
    private String image;
    private String brand;
    private String category;
    private String spec;
    private Integer sold;
    private Integer commentCount;
    private Integer status;
    private Boolean isAd;
    private List<String> suggestion;

    public ItemDoc(Item item) {
        this.id = item.getId();
        this.name = item.getName();
        this.price = item.getPrice();
        this.stock = item.getStock();
        this.brand = item.getBrand();
        this.image = item.getImage();
        this.category = item.getCategory();
        this.spec = item.getSpec();
        this.sold = item.getSold();
        this.commentCount = item.getCommentCount();
        this.status = item.getStatus();
        this.isAd = item.getIsAD();
        this.suggestion = Arrays.asList(this.brand,this.category);
    }
}
